﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ZX.WebApp.DesignForm.T4Model
{

    public class UItbPart1
    {
        public string BuildTextField(System.Data.DataRow row)
        {
            string _strForm = "";
            switch (row["ControlsType"].ToString())
            {
                case "textarea":  //多行文本
                        _strForm = string.Format("<textarea datafields=\"{0}\" id=\"{0}\"  name=\"{0}\" title=\"{1}\"  value=\"\" data-default-value=\"\" style=\"width: 400px; height: 75px\" ></textarea>", row["ColName"].ToString(), row["ColDesc"].ToString());
                    break;
                case "textfield"://单行文本
                    _strForm = FormatInputControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["CanNull"].ToString(), row["CType"].ToString());
                    break;
                case "radio":  //单选框
                        _strForm = string.Format("<input datafields=\"{0}\" id=\"{0}\" name=\"{0}\" title=\"{1}\" type=\"radio\" />", row["ColName"].ToString(), row["ColDesc"].ToString());
                    break;
                case "checkbox": //复选框
                        _strForm = string.Format("<input datafields=\"{0}\" id=\"{0}\" name=\"{0}\" title=\"{1}\" type=\"checkbox\" />", row["ColName"].ToString(), row["ColDesc"].ToString());
                    break;
                case "Date": //日期
                    _strForm = string.Format("<input style=\"width: 120px\" datafields=\"{0}\" id=\"{0}\" name=\"{0}\" title=\"{1}\" type=\"Date\" />", row["ColName"].ToString(), row["ColDesc"].ToString());
                    break;
                case "Time": //时间
                    _strForm = string.Format("<input style=\"width: 120px\" datafields=\"{0}\" id=\"{0}\" name=\"{0}\" title=\"{1}\" type=\"Time\" />", row["ColName"].ToString(), row["ColDesc"].ToString());
                    break;
                case "select": //下拉选择框
                    _strForm = string.Format("<select datafields=\"{0}\" id=\"{0}\" name=\"{0}\" title=\"{1}\"  ></select>", row["ColName"].ToString(), row["ColDesc"].ToString());
                    break;
                case "Hidden": //隐藏控件
                    _strForm = string.Format("<input  id=\"{0}\" name=\"{0}\" title=\"{1}\"  type=\"hidden\" />", row["ColName"].ToString(), row["ColDesc"].ToString());
                    break;
                case "u":  //选择用户
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "t":
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "c":  //培训客户
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "e": //职员
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "a": //课前辅导
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "b": // 培训课程
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "p":  //职位
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "d": //内部客户
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "s": //部门
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "pos": //调岗控件
                    _strForm = FormatPOSControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "dep": //跨门部门控件
                    _strForm = FormatDeptControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "m"://客户选择
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "f": //客户经理独立开发的客户
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "j"://缴款单客户选择
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "v"://选择客户经理
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "g": //业绩归属
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "z": //用户选择
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "o":
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "h"://选择客户总监
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "i":  //选择部门
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "6":  //用户[登陆名]
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
                case "5":  //用户[登陆名]
                    _strForm = FormatControls(row["ColName"].ToString(), row["ColDesc"].ToString(), row["ControlsType"].ToString());
                    break;
            }
            return _strForm;
        }

        public string FormatInputControls(string ColName, string ColDesc, string CanNull, string CType)
        {

            string _strForm = "<input style=\"width: 400px\" datafields=\"{0}\" id=\"{0}\"  name=\"{0}\" title=\"{1}\"  value=\"\" data-default-value=\"\" type=\"text\" ";
            switch (CType)
            {
                case "string":  //字符串
                        _strForm = string.Format(_strForm + " class=\"textInput large\"", ColName, ColDesc);
                    break;
                case "decimal":  //小数
                        _strForm = string.Format(_strForm + " class=\"textInput large validateNumber \"", ColName, ColDesc);
                    break;
                case "int":  //整数
                        _strForm = string.Format(_strForm + " class=\"textInput large validateInteger \"", ColName, ColDesc);
                    break;
                case "datetime":  //日期
                        _strForm = string.Format(_strForm + " class=\"textInput large validateDate \"", ColName, ColDesc);
                    break;
            }
            return _strForm + " />";
        }
        public string FormatControls(string ColName, string ColDesc, string ControlsType)
        {
            return string.Format("<input type=\"hidden\" datafields=\"{0}\"  id=\"{0}\" name=\"{0}\" class=\"yui-dept\"/><input id=\"txt{0}\" name=\"txt{0}\" type=\"text\"  readonly=\"true\" value=\"\" title=\"{1}\"  class=\"textInput small\"  dtype=\"{2}\"  /><button id=\"btn{0}\" name=\"{2}\" type=\"button\" value=\"\">选择</button>", ColName, ColDesc, ControlsType);
        }



        public string FormatDeptControls(string ColName, string ColDesc, string ControlsType)
        {
            return string.Format("<input type=\"hidden\" datafields=\"TRFDeptID\"  id=\"TRFDeptID\" name=\"TRFDeptID\" class=\"yui-dept\"/><input id=\"txtTRFDeptID\" name=\"txtTRFDeptID\" type=\"text\"  readonly=\"true\" value=\"\" title=\"{1}\"  class=\"textInput small\"  dtype=\"{2}\"  /><button id=\"btnTRFDeptID\" name=\"{2}\" type=\"button\" value=\"\">选择</button>", ColName, ColDesc, ControlsType);
        }

        public string FormatPOSControls(string ColName, string ColDesc, string ControlsType)
        {
            return string.Format("<input class=\"yui-dept\" datafields=\"TRFDeptID\" id=\"TRFDeptID\" name=\"TRFDeptID\" type=\"hidden\" /> <input class=\"yui-dept\" datafields=\"TRFPostName\" id=\"TRFDeptName\" name=\"TRFDeptName\" type=\"hidden\" /><input id=\"txt{0}\" name=\"txt{0}\" type=\"text\"  readonly=\"true\" value=\"\" title=\"{1}\"  class=\"textInput small\"  dtype=\"{2}\"  /><button id=\"btn{0}\" name=\"{2}\" type=\"button\" value=\"\">选择</button> <select datafields=\"{0}\" id=\"TRFPostID\" name=\"TRFPostID\" onchange=\"DatPost_Change(this)\"   title=\"{1}\"></select><input class=\"yui-dept\" datafields=\"TRFPostName\" id=\"TRFPostName\" name=\"TRFPostName\" type=\"hidden\" />", ColName, ColDesc, ControlsType);
        }
        public string StrConvFirstUpper(string str)
        {
            str = str.ToLower();
            System.Text.StringBuilder sb = new System.Text.StringBuilder(str);
            char cc = Char.ToUpper(sb[0]);
            sb.Replace(sb[0], cc, 0, 1);
            return sb.ToString();
        }
    }
}
    